package com.hy.ssm.biz.impl;

import com.hy.ssm.bean.ProductInfo;
import com.hy.ssm.biz.IProductInfoBiz;
import com.hy.ssm.mapper.IProductInfoMapper;
import com.hy.ssm.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Auther: HuYang
 * @Date: 2022/11/18 - 11 - 18 - 21:04
 * @Description: com.yc.snack.biz.impl
 * @version: 1.0
 */
@Service
public class ProductInfoBizImpl implements IProductInfoBiz {
    @Autowired
    private IProductInfoMapper productInfoMapper;
    @Override
    public int add(ProductInfo productInfo) {
        if(StringUtil.checkNull(productInfo.getGname(), productInfo.getPrice(), productInfo.getTno(), productInfo.getPics())) {
            return -1;
        }

        return productInfoMapper.add(productInfo);
    }

    @Override
    public List<ProductInfo> finds(Map<String,Object> map) {
        return productInfoMapper.finds(StringUtil.findByPageUtil(map));
    }

    @Override
    public Map<String, Object> findByFirst(Map<String,Object> map) {
        List<ProductInfo> list = productInfoMapper.finds(StringUtil.findByPageUtil(map));
        if(list == null || list.isEmpty()) {
            return Collections.emptyMap();  // 返回空集合，不是空对象
        }
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("total", productInfoMapper.total());
        result.put("rows", list);
        return result;
    }
}
